#include "nec_fs/file_writer.hpp"

namespace nec_fs {

FileWriter::FileWriter(const char *filename) {
  f = fopen(filename, "a+");
  total_size_ = 0;
}

int FileWriter::WriteStr(const char *line) {
  int l = strlen(line);
  int mix = fwrite(line, l, 1, f);
  total_size_ += mix * l;
  return mix * l;
}

size_t FileWriter::TotalSize() { return total_size_; }

FileWriter::~FileWriter() {
  if (f != nullptr) {
    fclose(f);
  }
}

} // namespace nec_fs
